home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Source / 10-InfoSystems / samba / samba-gen.frm.z / samba-gen.frm
Encoding:
Text File  |  1997-07-30  |  7.7 KB  |  304 lines

  1. #!/usr/bin/perl5
  2. #
  3. # samba-gen.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: samba-gen.frm,v 1.5 1997/06/19 22:26:33 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23. require "/usr/OnRamp/lib/java.pm";
  24.  
  25. $js_edit =
  26. "$js_standard;
  27. $js_error_box;
  28. $js_filename;
  29. $js_hostname;
  30. function checkForm(form) {
  31.     if (!testFileChars(form.workgroup.value)) {
  32.         errorBox(form.workgroup, \"The workgoup name cannot contain \"
  33.             + \"metacharacters.\");
  34.         return (false);
  35.     }
  36.     if (!testHostname(form.wins_server, form.wins_server.value, 
  37.         \"wins server\", 1)) return (false);
  38.     print = form.print_command.value;
  39.     ind = print.indexOf(\" \", 0);
  40.     if (ind == -1) {
  41.         if (!testFilename(form.print_command, \"print command\"))
  42.             return (false);
  43.     } else {
  44.         path = print.substring(0, ind);
  45.         if (!myTestFilename(form.print_command, path, \"print commant\")) return (false);
  46.         if (!myTestFileChars(form.print_command.value)) {
  47.             errorBox(form.print_command, \"The print command cannot contain \"
  48.                 + \"meta characters.\");
  49.             return (false);
  50.         }
  51.     }
  52.     return (true);
  53. }
  54. function myTestFilename(Ctrl, word, what) {
  55.         if (word == \"\") {
  56.                 errorBox (Ctrl, \"The \" + what + \" is required.\");
  57.                 return (false);
  58.         }
  59.         if (!myTestFileChars(word)) {
  60.                 errorBox (Ctrl, \"The \" + what + \" cannot \\ncontain \"
  61.                         + illegal + \" characters.\");
  62.                 return (false);
  63.         }
  64.         for(i = 0; i < word.length; i++) {
  65.                 if (word.charAt(i) == ' ') {
  66.                         errorBox (Ctrl, \"The \" + what + \" cannot \\ncontain spaces.\");
  67.                         return (false);
  68.                 }
  69.         }
  70.         if (word.charAt(0) != '/') {
  71.                 errorBox (Ctrl, \"The \" + what + \" must be fully qualified.\");
  72.                 return (false);
  73.         }
  74.         return (true);
  75. }
  76. function myTestFileChars(word) {
  77.         metaChars = \"{}()*!~<>?|[]'&^\$\@\#`\\\";:\";
  78.         for(j = 0; j < metaChars.length; j++) {
  79.                 illegal = metaChars.charAt(j);
  80.                 if (word.indexOf (illegal, 0) != -1) return (false);
  81.         } return (true);
  82. }";
  83.  
  84. $conf = "/usr/local/samba/lib/smb.conf";
  85. $dummy = "/usr/local/samba/lib/smb.conf.tmp";
  86. $myname = "samba-gen.cgi";
  87. $title = "SAMBA Configuration";
  88. $smbd = "/usr/local/samba/bin/smbd";
  89.  
  90. open(IN, "/usr/bsd/hostname |");
  91. $host = <IN>;
  92. close(IN);
  93. chop($host);
  94.  
  95. $defaults = "   server string = $host, samba %v\n"
  96.     . "   guest = nobody\n"
  97.     . "   wins support = yes\n"
  98.     . "   load printers = yes\n"
  99.     . "   printing = sysv\n"
  100.     . "   preserve case = yes\n"
  101.     . "   short preserve case = yes\n\n";
  102.  
  103.  
  104. if ( ! -e $smbd) {
  105.     print "Content-type: text/html\n\n";
  106.     &title_block($title);
  107.     &header_block($title);
  108.     print "<i>SAMBA software not installed.  Install subsystem 
  109.         </i><b>fw_samba.sw.base</b><i> from the freeware CD.</i>";
  110.     exit 0;
  111. }
  112.  
  113. &get_fields2;
  114.  
  115. &get_vals;
  116.  
  117. if (%fld) {
  118.     $help = $document_root . $ENV{"SCRIPT_NAME"};
  119.     $help =~ s/cgi$/hlp/;
  120.     exec $help if ($fld{'help'} eq "Help");
  121.  
  122.     if ($fld{'ok'}) { 
  123.         &doEdit; 
  124.         &get_vals; 
  125.         &editAccount; 
  126.     }
  127. } else { &editAccount; }
  128. exit 0;
  129.  
  130. sub get_fields2 {
  131.   my $buffer, $name, $value, $pair, @pairs;
  132.  
  133.   read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  134.  
  135.   @pairs = split(/&/, $buffer);
  136.  
  137.   foreach $pair (@pairs) {
  138.     ($name, $value) = split(/=/, $pair);
  139.     $value =~ tr/+\t/  /;
  140.     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
  141.  
  142.     $name = "xaster" if ($name eq "*");
  143.     $name =~ s/\+/ /g;
  144.  
  145.     $fld{$name} = $value;
  146.   }
  147. }
  148.  
  149. sub doEdit {
  150.     $added = 0;
  151.     open(IN, "< $conf");
  152.     open(OUT, "> $dummy");
  153.     while(<IN>) {
  154.         if ($_ =~ /\[global\]/) {
  155.             while(<IN>) {
  156.                 if ($_ =~ /\[.*\]/) { last; }
  157.             }
  158.  
  159.             print OUT "[global]\n";
  160.             &add_global;
  161.             $added = 1;
  162.     
  163.             print OUT $_;
  164.         } else { print OUT $_; }
  165.     }
  166.     close(IN);
  167.     close(OUT);
  168.     rename($dummy, $conf);
  169.  
  170.     if ($added == 0) {
  171.         open(OUT, "> $conf");
  172.         print OUT "[global]\n";
  173.         &add_global;
  174.         close(OUT);
  175.     }
  176.  
  177.     if ($fld{'enable'} eq "Yes") {
  178.         system("/etc/chkconfig", "samba", "on");
  179.         unless (fork) {
  180.             unless (fork) {
  181.                 sleep 1 until getppid == 1;
  182.                 system("/etc/init.d/samba stop > /dev/null 2>&1");
  183.                 system("/etc/init.d/samba start > /dev/null 2>&1");
  184.                 exit 0;
  185.             }
  186.             exit 0;
  187.         }
  188.         wait;
  189.     } else {
  190.         if (!fork) {
  191.             system("/etc/chkconfig", "samba", "off");
  192.             system("/etc/init.d/samba stop > /dev/null");
  193.             exit 0;
  194.         }
  195.     }
  196. }    
  197.  
  198. sub add_global {    
  199.     if ($fld{'browse'} eq "Yes") {
  200.         print OUT "   preferred master = yes\n",
  201.             "   os level = 50\n";
  202.     }
  203.     if ($fld{'domain'} eq "Yes") {
  204.         print OUT "   domain master = yes\n";
  205.     }
  206.     if ($fld{'workgroup'}) {
  207.         print OUT "   workgroup = $fld{'workgroup'}\n";
  208.     }
  209.     if ($fld{'wins_server'}) {
  210.         print OUT "   wins server = $fld{'wins_server'}\n";
  211.     }
  212.     if ($fld{'print_command'}) {
  213.         print OUT "   print command = $fld{'print_command'}\n";
  214.     }
  215.     print OUT $defaults;
  216. }
  217.     
  218. sub get_vals {
  219.     $val{'browse'} = "No";
  220.     $val{'domain'} = "No";
  221.  
  222.     open(IN, "< $conf");
  223.     
  224.     $read_lines = 0;
  225.     while(<IN>) {
  226.         if ($_ =~ /\[global\]/) { $read_lines = 1; next; }
  227.         elsif ($_ =~ /\[.*\]/) { $read_lines = 0; next; }
  228.         next if $read_lines == 0;
  229.         next if substr($_,0,1) eq ";";
  230.  
  231.         if ($_ =~ /(.*)=(.*[^\s].*)/) {
  232.             $parm = $1;
  233.             $value = $2;
  234.  
  235.             $parm =~ /^\s*([^\s].*[^\s])\s*$/; $parm = $1;
  236.             $value =~ /^\s*([^\s].*)$/; $value = $1;
  237.  
  238.             if (($parm eq "preferred master" && $value eq "yes") 
  239.                 || ($parm eq "os level" && $value > 34)) {
  240.                 $val{'browse'} = "Yes";
  241.             }
  242.  
  243.             if ($parm eq "domain master" && $value eq "yes") {
  244.                 $val{'domain'} = "Yes";
  245.             }
  246.  
  247.             if ($parm eq "wins server") {
  248.                 $val{"wins_server"} = $value;
  249.             }
  250.  
  251.             if ($parm eq "workgroup") {
  252.                 $val{$parm} = $value;
  253.             }
  254.  
  255.             if ($parm eq "print command") {
  256.                 $val{"print_command"} = $value;
  257.             }
  258.         }
  259.     }
  260.  
  261.     $chk = system ("/etc/chkconfig", "samba");
  262.     if ($chk) { $val{'enable'} = "No"; }
  263.     else { $val{'enable'} = "Yes"; }
  264. }    
  265.  
  266. sub editAccount {
  267.     print "Content-type: text/html\n\n";
  268.     
  269.         &js_title_block($title,$js_edit);
  270.  
  271.         &header_block("SAMBA Configuration");
  272.  
  273.     print "$message<br>";
  274.         
  275.     print "<form name=StandardForm action=$myname method=post "
  276.         . "onSubmit=\"return runSubmit()\">";
  277.  
  278.     print "<center><table width=450>\n";
  279.  
  280.     print "<tr><th align=left>Enable Samba?\n",
  281.         "<td><b>", &radio("enable", $val{'enable'}, "Yes", "No"), "</b></td></tr>\n";
  282.  
  283.     print "<tr><th align=left>Name of workgroup:\n",
  284.         "<td>", &text("workgroup", $val{'workgroup'}, 20), "</td></tr>\n";
  285.  
  286.     print "<tr><th align=left>Set this server to be a browse master?\n",
  287.         "<td><b>", &radio("browse", $val{'browse'}, "Yes", "No"), "</b></td></tr>\n";
  288.  
  289.     print "<tr><th align=left>Set this server to be a domain master?\n",
  290.         "<td><b>", &radio("domain", $val{'domain'}, "Yes", "No"), "</b></td></tr>\n";
  291.  
  292.     print "<tr><th align=left>Name of network wins server:\n",
  293.         "<td>", &text("wins_server", $val{'wins_server'}, 20), "</td></tr>\n";
  294.  
  295.     print "<tr><th align=left>Print command:\n",
  296.         "<td>", &text("print_command", $val{'print_command'}, 20), "</td></tr>\n";
  297.         
  298.     print "</table></center><br><br>\n";
  299.  
  300.     print &js_buttons('ok','Ok','onClick="markOK()"',
  301.                     'onClick="markOther()"');
  302.         print "</form></body></html>";
  303. }
  304.